import axios from "axios";
import config from "../config/Config.js";

const speHttp={
    BASE_URL: config.BASE_URL + "/manager",
    /**
     * 新增规格项
     * @param {*} entry 
     * @param {*} callBack 
     */
    saveEntry(entry,callBack){
        axios.post(this.BASE_URL + "/itemSpecificationsEntry/save",entry)
        .then(res=>callBack(res.data));
    },

    /**
     * 分页查询指定规格编号的规格项列表
     * @param {*} speId 
     * @param {*} page 
     * @param {*} limit 
     * @param {*} callback 
     */
    queryEntryByPage(speId,page=1,limit=10,callback){
        axios.get(this.BASE_URL + "/itemSpecificationsEntry/queryByPage?page="+page+"&limit="+limit+"&speId="+speId)
        .then(res=>callback(res.data));
    },

    /**
     * 新增规格
     * @param {*} spe 
     * @param {*} callback 
     */
    save(spe,callback){
        axios.post(this.BASE_URL + "/itemSpecifications/save",spe).then(res=>callback(res.data));
    },

    /**
     * 多添加分页查询
     */
    queryByPage(itemSpe,page=1,limit=10,callback){
        // 拼接url
        let url = this.BASE_URL + "/itemSpecifications/queryByPage?page=" + page + "&limit=" + limit;
        if(itemSpe){
            if(itemSpe.speName){
                url += "&speName=" + itemSpe.speName;
            }
            if(itemSpe.status){
                url += "&status=" + itemSpe.status;
            }
        }
        // 查询
        axios.get(url).then(res=>callback(res.data));
    }
}

export default speHttp;